﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiracTCC.Business
{
    public class FrameInfo
    {
        public int FrameNumber { get; set; }
        public int? Ref1 { get; set; }
        public int? Ref2 { get; set; }
        public string PictureType { get; set; }
        public string SubBlockLenght { get; set; }
        public string MVLenght { get; set; }
        public string BlockSeparation { get; set; }
        public string References
        {
            get
            {
                return GetReferences();
            }
        }

        private string GetReferences()
        {
            string refs = string.Empty;

            if (Ref1.HasValue)
            {
                refs += ", Ref1: " + Ref1.Value.ToString();
            }
            if (Ref2.HasValue)
            {
                refs += ", Ref2: " + Ref2.Value.ToString();
            }

            if (!string.IsNullOrEmpty(refs))
            {
                return refs.Substring(2);
            }
            else
            {
                return "Nenhuma referência";
            }
        }

        public int[] GetSubBlockLenghtArray()
        {
            int[] lenght = new int[2];

            if(string.IsNullOrEmpty(SubBlockLenght) || !SubBlockLenght.Contains("x"))
                return new int[2];

            string[] text = SubBlockLenght.Split('x');

            lenght[0] = int.Parse(text[0].Trim());
            lenght[1] = int.Parse(text[1].Trim());

            return lenght;
        }
    }
}
